require('../../assets/css/reset.css')
require('../../assets/css/normalize.css')
require('../../assets/iconf/iconfont.css')
require('./play.less')

let axios = require('axios')
// 获取登录时储存的用户信息
let user = JSON.parse(localStorage.getItem('login'))

// 设置axios请求头,添加token
axios.defaults.headers.authorization = "Bearer " + user.token;

// axios.get('http://47.96.154.185:3701/api/train/courseDetail',{
//     params:{
//         id:id
//     }
// })

let now = document.querySelector('#now')
let sum = document.querySelector('#sum')
let video = document.querySelector('#video')
let title = document.querySelector('#title')
let bakc = document.querySelector('.bakc')
let next = document.querySelector('.next')
let play = document.querySelector('.play')
let stop = document.querySelector('.stop')
let mask = document.querySelector('.mask')
let green = document.querySelector('.green')
let red = document.querySelector('.red')
let bofang = document.querySelector('.bofang')


let fragments = JSON.parse(localStorage.getItem('fragments'))
console.log(fragments);

sum.textContent = fragments.length

let num = 0
sum.textContent = fragments.length
let player = function () {
    now.textContent = num + 1
    title.textContent = fragments[num].title
    bofang.textContent = fragments[num].title
    video.src = `http://47.96.154.185:3701${fragments[num].videoUrl}`
}

player()

video.addEventListener('ended', function () {
    num++
    if (num == fragments.length) {
        num = 0
    }
    player()
 
})

next.addEventListener('click', function () {
    num++
    if (num == fragments.length) {
        num = 0
    }
    player()
})

bakc.addEventListener('click',function(){
    num--
    if(num<0){
        num = 3
    }
    player()
})
stop.addEventListener('click',function(){
    video.play()
    stop.className = 'stop none'
    play.className = 'play'
    mask.className = 'mask none'
})

play.addEventListener('click',function(){
    video.pause()
    stop.className = 'stop '
    play.className = 'play none'
    mask.className = 'mask '
})

green.addEventListener('click',function(){
    video.play()
    mask.className = 'mask none'
    stop.className = 'stop none'
    play.className = 'play'
})

red.addEventListener('click',function(){
    video.pause()
    // location.href = './dedail.html'
    history.go(-1)
})

